﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class test
    {
        private readonly string sqlCommandString = "select * from Student";

        private readonly string connectionString = "server=.;database=Admin;uid=sa;pwd=123456789";

        public static void Student()
        {

            string connectionString = "server=.;database=Admin;uid=sa;pwd=123456789";

            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            string sqlCommandString = "select * from Student";

            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);

            var sdr = sqlCommand.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}", "Id", "姓名", "成绩");

            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sdr["Id"], sdr["StudentName"], sdr["score"]);
            }
            sqlConnection.Close();

        }

        public void Student1()
        {

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommandString, connectionString);

            DataTable dataTable = new System.Data.DataTable();

            dataAdapter.Fill(dataTable);
            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "姓名", "成绩");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["Id"], dataTable.Rows[i]["StudentName"], dataTable.Rows[i]["Score"]);
            }





        }
    }
}
